package com.alibaba.org.service.impl;

import com.alibaba.basic.query.BaseQuery;
import com.alibaba.basic.util.PageList;
import com.alibaba.org.domain.Employee;
import com.alibaba.org.mapper.EmployeeMapper;
import com.alibaba.org.service.IEmployeeService;
import com.alibaba.basic.service.impl.BaseServiceImpl;
import com.alibaba.system.domain.Role;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 业务实现类：
 */
@Service
public class EmployeeServiceImpl extends BaseServiceImpl<Employee> implements IEmployeeService {

    @Resource
    private EmployeeMapper employeeMapper;

    @Override
    public PageList<Employee> queryPage(BaseQuery query) {
        //先查询总数量
        Long totals = employeeMapper.queryCount(query);

        if(totals < 1){
            return new PageList<Employee>();
        }
        //再查询当前页的分页数据
        List<Employee> data = employeeMapper.queryData(query);
        for (Employee employee : data) {
            List<Long> roles = employeeMapper.findRoleIdByEmpId(employee.getId());
            employee.getRoles().addAll(roles);
        }

        return new PageList<Employee>(totals,data);
    }
}
